﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace SmartProject.BusinessRules
{
    /// <summary>
    /// A Sprint Cycle cannot be more than 30 days long.
    /// </summary>
    public class SprintMaxMinLength : BusinessRule
    {
        public override string Name
        {
            get { return ""; }
        }

        public override string Description
        {
            get { return ""; }
        }

        public override void Implement(Entity data)
        {
            if (data.StoredProc == "smartProject_AddSprint" ||
                data.StoredProc == "smartProject_UpdateSprint")
            {
                int estimatedDays = (int)data.GetAttributeValue("EstimatedDays");
                if (estimatedDays > 31)
                {
                    throw new Exceptions.BusinessRuleViolation("A Sprint Cycle cannot be longer than 31 days.");
                }
                else if (estimatedDays < 1)
                {
                    throw new Exceptions.BusinessRuleViolation("A Sprint Cycle cannot be shorter than 1 day.");
                }
            }
        }

        public override bool QueryBooleanProperty(string propertyName)
        {
            return NotQueryable;
        }
    }
}
